import com.google.common.collect.Lists;
import expedia.HotelBrand;
import expedia.RoomArea;
import org.apache.commons.lang3.time.DateFormatUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @description: 测试
 * @author: yuanjianpeng5
 * @createdate: 2020-02-04 14:11
 * @lastdate:
 */

public class Test2 {
    public static void main(String[] args) {
//        List<HotelBrand> hotelBrands = Lists.newArrayList();
//        for (int i=0; i<10; i++) {
//            HotelBrand item = new HotelBrand();
//            item.setId(i);
//            item.setName("brand"+i);
//            hotelBrands.add(item);
//        }
//        HotelBrand hotelBrand = hotelBrands.stream().filter(e ->
//                e.getName().equals("test")).findFirst().orElse(null);

//        System.out.println(hotelBrands.size());
//        System.out.println(getEanHttpResponse(null, 0));
//        Integer i = null;
//        if (i != null && i.intValue() > 5) {
//            System.out.println("yes");
//        } else {
//            System.out.println("no");
//        }
//        System.out.println(i+5);

    }

    public static String getEanHttpResponse(String url, int retryNum) {
        String responseInfo = null;
        while (true) {
            try {
                responseInfo = url.replace('a','b');
                break;
            } catch (Exception e) {
                System.out.println("【getEanHttpResponse】ean接口调用错误, url:{}, message:{}");
                retryNum--;
                if (retryNum < 0) {
                    break;
                }
                System.out.println("【getEanHttpResponse】ean接口调用错误重试");
            }
        }
        return responseInfo;
    }

    public static void pageTest() {
        List<HotelBrand> hotelBrandList = new ArrayList<>();
        for (int i = 1; i < 48; i++) {
            HotelBrand hotelBrand = new HotelBrand();
            hotelBrand.setId(i);
            hotelBrand.setName("brand" + i);
            hotelBrandList.add(hotelBrand);
        }
        int totalPage = hotelBrandList.size() / 10;
        for (int i = 0; i < totalPage; i++) {
            changeName(hotelBrandList.subList(i*10, (i+1)*10));
        }
        hotelBrandList.stream().forEach(hotelBrand -> {
            System.out.println(hotelBrand.getName());
        });
    }

    public static void sortArray() {
        //        int[] a = {9, 8, 7, 2, 3, 4, 1, 0, 6, 5};
//        String[] attr = {"2646", "2644", "54"};
//        Arrays.sort(attr, (o1, o2) -> (int) o2 - (int) o1);
//        for(String arr:attr) {
//            System.out.print(arr + " ");
//        }
    }

    public static void sortMapByKey() {
        Map<String, String> map = new HashMap<>();
        map.put("2644", "2644");
        map.put("2646", "2646");
        map.put("54", "54");
        map.put("363", "363");
//        Object[] objects = map.keySet().toArray();
//        Arrays.sort(objects, (o1, o2) -> (Integer) o2 - (Integer) o1);
//        for (Object key : objects) {
//            System.out.println(key);
//        }

        List<Map.Entry<String, String>> list = new LinkedList<>(map.entrySet());
//        Collections.sort(list, Comparator.comparingInt(o -> Integer.parseInt((o.getKey())))); // 正序
        Collections.sort(list, (o1, o2) -> Integer.parseInt(o2.getKey()) - Integer.parseInt(o1.getKey())); // 倒序
        //拼装policy
        list.stream().forEach(entry -> {
            if (null != entry.getKey()) {
                System.out.println(entry.getKey() + "\t" + entry.getValue());
            }
        });
    }

    public static void dataformat() {
        //        try {
//            System.out.println(new SimpleDateFormat("yyyy").parse("1983"));
//        } catch (ParseException e) {
//            e.printStackTrace();
//        }
    }

    public static void changeName(List<HotelBrand> hotelBrands) {
        for (HotelBrand hotelBrand : hotelBrands) {
            if (hotelBrand.getId() % 3 == 0) {
                hotelBrand.setName(hotelBrand.getName() + "is 3s");
            }
        }
    }
}